//
//  QLDownloadOperation.m
//  QLOperation
//
//  Created by Shrek on 15/5/28.
//  Copyright (c) 2015年 Personal. All rights reserved.
//

/** QLDEBUG Print | M:method, L:line, C:content*/
#ifdef DEBUG
#define QLLog(FORMAT, ...) fprintf(stderr,"M:%s|L:%d|C->%s\n", __FUNCTION__, __LINE__, [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);
#else
#define QLLog(FORMAT, ...)
#endif

#import "QLDownloadOperation.h"

@implementation QLDownloadOperation

/** 实现自定义的NSOperation,就需要实现main方法,在这个方法中做出相应的实现 */
- (void)main {
    //QLLog(@"%@-%@", self.url, [NSThread currentThread]);
    NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:self.url]];
    UIImage *image = [[UIImage alloc] initWithData:data];
    if ([self.delegate respondsToSelector:@selector(downloadOperation:DidFinishDownloadImage:)]) {
        dispatch_async(dispatch_get_main_queue(), ^{
           [self.delegate downloadOperation:self DidFinishDownloadImage:image];
        });
    }
}

@end
